package com.ruiyun.ruinews.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ruiyun.ruinews.R;
import com.ruiyun.ruinews.entity.HeadLines;

import java.util.List;

/**
 * Created by zouhui on 16/1/8.
 */
public class NewsClassRecycleAdapter extends RecyclerView.Adapter{
    private Context context;
    private List<HeadLines> data;
    private List<Integer> headerView;

    public NewsClassRecycleAdapter(Context context, List<HeadLines> data,List<Integer> headerView) {
        this.context = context;
        this.data = data;
        this.headerView = headerView;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (headerView!=null && viewType == 1){
            View view = LayoutInflater.from(context).inflate(R.layout.item_newscalss_turns,parent,false);
            HeaderViewHolader holader = new HeaderViewHolader(view);
            return holader;
        }else{
            View view = LayoutInflater.from(context).inflate(R.layout.item_newscalss_turns,parent,false);
            NewsClassViewHolder holder = new NewsClassViewHolder(view);
            return holder;
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (getItemViewType(position)==1){
            ((HeaderViewHolader)holder).headerOne.setImageResource(headerView.get(0));
            ((HeaderViewHolader)holder).headerTwo.setImageResource(headerView.get(1));
            ((HeaderViewHolader)holder).headerThree.setImageResource(headerView.get(2));
            ((HeaderViewHolader)holder).headerFour.setImageResource(headerView.get(3));
        }else{
            ((NewsClassViewHolder)holder).headIv.setImageResource(R.mipmap.ic_launcher);
            ((NewsClassViewHolder)holder).digest.setText("文摘");
            ((NewsClassViewHolder)holder).title.setText("标题");
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (headerView == null)return 0;
        if (position == 0)return 1;
        return 0;
    }

    @Override
    public int getItemCount() {
        return 100;
    }

    class NewsClassViewHolder extends RecyclerView.ViewHolder{
        private TextView title,digest;
        private ImageView headIv;
        public NewsClassViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tv_newsclass_newsTitle);
            digest = (TextView) itemView.findViewById(R.id.tv_newclass_newsDigest);
            headIv = (ImageView) itemView.findViewById(R.id.iv_newsclass_headImg);
        }
    }
    class HeaderViewHolader extends RecyclerView.ViewHolder{
        private ImageView headerOne,headerTwo,headerThree,headerFour;
        public HeaderViewHolader(View itemView) {
            super(itemView);
            headerOne = (ImageView) itemView.findViewById(R.id.iv_newsclass_turns_one);
            headerTwo = (ImageView) itemView.findViewById(R.id.iv_newsclass_turns_two);
            headerThree = (ImageView) itemView.findViewById(R.id.iv_newsclass_turns_three);
            headerFour = (ImageView) itemView.findViewById(R.id.iv_newsclass_turns_four);
        }
    }
}
